package com.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bean.ReturnApply;
import com.bean.ReturnApplyMaterial;
import com.bean.Stock;
import com.service.StockService;
import com.sun.org.apache.regexp.internal.recompile;
import com.util.TimeUtil;

/**
 * @author author : 张鹏
 * @date createTime：2018年2月22日 下午6:21:30
 * @Description: 该类的功能描述
 */
@Controller
@RequestMapping("stock")
public class StockController {
	@Autowired
	private StockService stockService;

	private Stock stock;
	


	

	/**
	 * 根据原料id 查询库存数量
	 * 
	 * @param materialId
	 * @return
	 */
	@RequestMapping("getStockByMaterialIdAjax")
	@ResponseBody
	public Double getStockByMaterialIdAjax(int materialId) {
		return stockService.getStockQuantity(materialId);
	}

	/**
	 * 查询仓库中的所有库存
	 * 
	 * @return
	 */
	@RequestMapping("getAllStockAjax")
	@ResponseBody
	public List<Stock> getAllStockAjax() {
		return stockService.getAllStock();
	}

	/**
	 * 获得待入库的商品
	 * 
	 * @param state
	 * @return
	 */
	@RequestMapping("getWaitToinStockAjax")
	@ResponseBody
	public List<Stock> getWaitToinStockAjax(int state) {
		return stockService.getStockByState(state);
	}

	/**
	 * 入库
	 */
	@RequestMapping("inStockAjax")
	@ResponseBody
	public int inStockAjax() {
		stock = new Stock();
		stock.setCreateById(1);// 暂时手动设置
		stock.setCreateTime(TimeUtil.formatTime());
		stock.setState(1);
		return stockService.inStock(stock);
	}

	/**
	 * 查询入库记录
	 * 
	 * @return
	 */
	@RequestMapping("getInStockRecordAjax")
	@ResponseBody
	public List<Stock> getInStockRecordAjax() {
		return stockService.getInStockRecord();
	}

	/**
	 * 查询出库记录
	 * 
	 * @return
	 */
	@RequestMapping("getOutStockRecordAjax")
	@ResponseBody
	public List<Stock> getOutStockRecordAjax() {
		return stockService.getOutStockRecord();
	}

	/**
	 * 根据商品编码或名称查询库存
	 * 
	 * @param searchWords
	 * @return
	 */
	@RequestMapping("getStockByMaterialIdOrMaterialNameAjax")
	@ResponseBody
	public List<Stock> getStockByMaterialIdOrMaterialNameAjax(String searchWords) {
		return stockService.getStockByMaterialIdOrMaterialName(searchWords);
	}

}
